package edu.xja.service.impl;

import edu.xja.dao.AdminDao;
import edu.xja.entity.Admin;
import edu.xja.service.AdminService;
import edu.xja.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class AdminServiceImpl implements AdminService {
    private AdminDao adminDao;
    {
        SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtil.getSqlSessionFactory();
        SqlSession sqlSession=sqlSessionFactory.openSession();
        adminDao=sqlSession.getMapper(AdminDao.class);
    }
    public Admin adminLogin(String adminName, String adminPass) {
        if(adminName==null || adminPass==null){
            return null;
        }

        Admin admin=adminDao.getAdminByAdminName(adminName);
        if(admin==null){
            return null;
        }
        if(null!=admin.getAdminPass() && adminPass.equals(admin.getAdminPass())){
            //合法用户
            return admin;
        }

        return null;


    }
}
